<?php
/**
 * Created by PhpStorm.
 * User: liuhong
 * Date: 2018/11/26
 * Time: 下午6:05
 */

namespace Api\Controller;


use Api\Service\ShareService;

class ShareController extends BaseController
{
    //查询类型
    public function getType(){
        $type_name=I('post.type_name');
        $where=array();
        if(!empty($type_name)){
            $where['type_name']=array('like',"%{$type_name}%");
        }

        $filed='type_id,type_name';
        //dump($where);die;
        $type_info=ShareService::S()->queryType($where,$filed);
        if($type_info){
            $this->ajax(200,'success',$type_info);
        }else{
            $this->ajax(202,'没有数据',array());
        }
    }

    //查询分享数据
    public function getShareInfoByType(){
        $type_ids=I('post.type_ids');
        $where=array();
        $where['ischeck'] = 1;
        if(!empty($type_ids)){
            $where['waoo_share.share_type']=array('in',$type_ids);
        }
        $page=I('post.page');
        if($page<=1){
            $page=1;
        }
        $page_num=20;
        $shareInfo=ShareService::S()->queryShare($where,$page,$page_num);
        $count=ShareService::S()->countShare($where);
        if($shareInfo){
            foreach ($shareInfo as $k=>$v){
                if(empty($shareInfo[$k]['share_thumb'])){
                    unset($shareInfo[$k]);
                    continue;
                }
                if($shareInfo[$k]['collections_id']){
                    $shareInfo[$k]['is_collections']=1;
                }else{
                    $shareInfo[$k]['is_collections']=0;
                }
                unset($shareInfo[$k]['collections_id']);
                $shareInfo[$k]['share_copy']=(($shareInfo[$k]['share_text']));
                $shareInfo[$k]['share_text']=nl2br(($shareInfo[$k]['share_text']));

                $shareInfo[$k]['share_data']=htmlspecialchars_decode($shareInfo[$k]['share_data']);
                $shareInfo[$k]['create_time']=date('Y-m-d',strtotime($v['create_time']));
                $shareInfo[$k]['share_pic']=C('UPYUN_DOMAIN').$shareInfo[$k]['share_pic'];//$goodsList[$k]["grade{$this->member['grade_id']}_price"];

                $thumb=json_decode($v['share_thumb'],true);//$goodsList[$k]["grade{$this->member['grade_id']}_price"];
                foreach ($thumb as $sk=>$sv){
                    if(empty($sv)){
                        unset($thumb[$sk]);
                        continue;
                    }
                    $thumb[$sk]=C('UPYUN_DOMAIN').$sv;
                }
                if(empty($thumb)){
                    $thumb=array();
                }
                $shareInfo[$k]['share_thumb']=$thumb;
                $shareInfo[$k]['video_thumb']=json_decode($v['video_thumb'],true);//$goodsList[$k]["grade{$this->member['grade_id']}_price"];
                //$shareInfo[$k]['video_thumb']=trim($shareInfo[$k]['video_thumb']);
                if(empty($shareInfo[$k]['video_thumb'])){
                    $shareInfo[$k]['video_thumb']=array();
                }
            }
            $data['code']=200;
            $data['msg']='success';
            $data['data']=$shareInfo;
            $data['page_count']=ceil($count/$page_num);
            $this->ajaxReturn($data);
        }else{
            $this->ajax(200,'没有数据');
        }
    }

}